package com.witframework.web.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

public class NoRightClickTag extends BodyTagSupport {
	private String sBody = null;
	private boolean cond = true;

	public void setCond(boolean paramBoolean) {
		this.cond = paramBoolean;
	}

	public boolean getCond() {
		return this.cond;
	}

	public int doAfterBody() throws JspException {
		BodyContent localBodyContent = getBodyContent();
		if (localBodyContent != null) {
			this.sBody = localBodyContent.getString();
			localBodyContent.clearBody();
		}
		return 0;
	}

	public int doEndTag() throws JspException {
		if (!(this.cond)) {
			dropData();
			return 6;
		}
		StringBuffer localStringBuffer = new StringBuffer("");
		if (this.sBody == null)
			this.sBody = "";
		else
			this.sBody = this.sBody.trim();
		localStringBuffer.append("\n<script language=\"JavaScript\">\n");
		localStringBuffer.append("<!--\n");
		if (this.sBody.length() > 0)
			localStringBuffer.append("var message=\"" + this.sBody + "\";\n");
		localStringBuffer.append("///////////////////////////////////\n");
		localStringBuffer.append("function clickIE4(){\n");
		localStringBuffer.append("if (event.button==2){\n");
		if (this.sBody.length() > 0)
			localStringBuffer.append("alert(message);\n");
		localStringBuffer.append("return false;\n");
		localStringBuffer.append("} }\n");
		localStringBuffer.append("function clickNS4(e){\n");
		localStringBuffer.append("if (document.layers||document.getElementById&&!document.all){");
		localStringBuffer.append("if (e.which==2||e.which==3){");
		if (this.sBody.length() > 0)
			localStringBuffer.append("alert(message);");
		localStringBuffer.append("return false; } } }\n");
		localStringBuffer.append("if (document.layers){\n");
		localStringBuffer.append("document.captureEvents(Event.MOUSEDOWN);\n");
		localStringBuffer.append("document.onmousedown=clickNS4;\n");
		localStringBuffer.append("}\n");
		localStringBuffer.append("else if (document.all&&!document.getElementById){\n");
		localStringBuffer.append("document.onmousedown=clickIE4;\n");
		localStringBuffer.append("}\n");
		localStringBuffer.append("document.oncontextmenu=new Function(\"");
		if (this.sBody.length() > 0)
			localStringBuffer.append("alert(message);");
		localStringBuffer.append("return false;\")\n");
		localStringBuffer.append("// -->\n");
		localStringBuffer.append("</script>\n");
		try {
			this.pageContext.getOut().write(localStringBuffer.toString());
		} catch (Exception localException) {
			throw new JspException("Could not write data " + localException.toString());
		}
		dropData();
		return 6;
	}

	public void release() {
		dropData();
		super.release();
	}

	private void dropData() {
		this.sBody = null;
		this.cond = true;
	}
}